﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TMI85303.Utils
{
    /// <summary>
    /// 单例实现工具类，使用时，继承自该类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class Singleton<T> where T : class
    {
        private static readonly Lazy<T> instance = new(() => CreateInstanceOfT());

        public static T Instance => instance.Value;

        protected Singleton()
        {

        }

        private static T CreateInstanceOfT()
        {
            return Activator.CreateInstance(typeof(T), true) as T;
        }
    }
}
